/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * NewChronologicalPanel.java
 *
 * Created on Oct 10, 2011, 1:39:56 PM
 */
package nl.fontys.sofa.odr.odrvpplugin.dialog;

import com.vp.plugin.view.IDialog;

/**
 *
 * @author Tim Aerdts
 */
public class NewDiagramPanel extends javax.swing.JPanel {

    private IDialog dialog;
    private String name = "";
    private boolean canceled = false;
    private boolean finished = false;
    private boolean next = false;

    /** Creates new form NewChronologicalPanel */
    public NewDiagramPanel(String diagramType) {
        initComponents();
        nameExplanation.setText("Enter a name for the new " + diagramType + "!");
        errorLabel.setVisible(false);
        nextButton.requestFocusInWindow();
        nextButton.requestFocus();
        nameTextField.setText("New "+diagramType);
    }

    public void setDialog(IDialog dialog) {
        this.dialog = dialog;
    }

    public boolean wasCanceled() {
        return canceled;
    }

    public boolean wasFinished() {
        return finished;
    }

    public boolean wasNext() {
        return next;
    }

    public String getDiagramName() {
        return name;
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("all")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        nextButton = new javax.swing.JButton();
        nameTextField = new javax.swing.JTextField();
        nameLabel = new javax.swing.JLabel();
        nameExplanation = new javax.swing.JLabel();
        cancelButton = new javax.swing.JButton();
        finishButton = new javax.swing.JButton();
        errorLabel = new javax.swing.JLabel();

        nextButton.setText("Next");
        nextButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                nextButtonActionPerformed(evt);
            }
        });

        nameLabel.setText("Name:");

        nameExplanation.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        nameExplanation.setText("Enter a name for the new chronological view");

        cancelButton.setText("Cancel");
        cancelButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cancelButtonActionPerformed(evt);
            }
        });

        finishButton.setText("Finish");
        finishButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                finishButtonActionPerformed(evt);
            }
        });

        errorLabel.setForeground(new java.awt.Color(255, 0, 0));
        errorLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        errorLabel.setText("error");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(cancelButton)
                        .addGap(6, 6, 6)
                        .addComponent(finishButton)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(nextButton)
                        .addGap(45, 45, 45))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(nameExplanation, javax.swing.GroupLayout.DEFAULT_SIZE, 435, Short.MAX_VALUE)
                        .addContainerGap())
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(errorLabel, javax.swing.GroupLayout.DEFAULT_SIZE, 435, Short.MAX_VALUE)
                        .addContainerGap())
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(nameLabel)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(nameTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 360, Short.MAX_VALUE)
                        .addGap(45, 45, 45))))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(28, Short.MAX_VALUE)
                .addComponent(nameExplanation)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(errorLabel)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(nameLabel)
                    .addComponent(nameTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(cancelButton)
                    .addComponent(finishButton)
                    .addComponent(nextButton))
                .addContainerGap())
        );
    }// </editor-fold>//GEN-END:initComponents

    private void nextButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_nextButtonActionPerformed
        evt.getID(); //to avoid unused formal paramter
        if (validName()) {
            next = true;
            name = nameTextField.getText();
            if (dialog != null) {
                dialog.close();
            }
        }else{
            errorLabel.setText("Invalid Name!");
            errorLabel.setVisible(true);
        }
    }//GEN-LAST:event_nextButtonActionPerformed

    private void finishButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_finishButtonActionPerformed
        evt.getID(); //to avoid unused formal paramter
        if (validName()) {
            finished = true;
            name = nameTextField.getText();
            if (dialog != null) {
                dialog.close();
            }
        }else{
            errorLabel.setText("Invalid Name!");
            errorLabel.setVisible(true);
        }
    }//GEN-LAST:event_finishButtonActionPerformed

    private boolean validName() {
        String nameString = nameTextField.getText();
        return !nameString.equals("");
    }

    private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelButtonActionPerformed
        evt.getID(); //to avoid unused formal paramter
        canceled = true;
        if (dialog != null) {
            dialog.close();
        }
    }//GEN-LAST:event_cancelButtonActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton cancelButton;
    private javax.swing.JLabel errorLabel;
    private javax.swing.JButton finishButton;
    private javax.swing.JLabel nameExplanation;
    private javax.swing.JLabel nameLabel;
    private javax.swing.JTextField nameTextField;
    private javax.swing.JButton nextButton;
    // End of variables declaration//GEN-END:variables
}
